<xsl:stylesheet version="2.0" xmlns:foo="http://something" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns="http://www.w3.org/1999/xhtml">

	<xsl:import href="/apps/engine/utils/translate_fct.xsl"/>

	<xsl:template match="/">
		<html>
			<head>
				<xforms:model>
					<xforms:instance id="groups" src="input:instance"/>
					<xforms:submission resource="/portal/main/" method="post" replace="all" id="submit"/>
					<xforms:submission resource="/univers/create" method="get" replace="instance" instance="groups" id="groups-creation"/>
					<xforms:submission resource="/univers/new" method="post" replace="all" id="groups-new"/>
					<xforms:submission resource="/univers/delete" method="post" replace="all" id="groups-delete"/>
					<xforms:submission resource="/univers/join" method="post" replace="all" id="join-group"/>
					<xforms:bind ref="/groups" relevant="count(group)&gt;1"/>

				</xforms:model>
				<title>
					<xsl:value-of select="/data/appname"/>
					<xsl:if test="/data/copName != ''"> - <xsl:value-of select="/data/copName"/>
					</xsl:if>
				</title>

				<link rel="stylesheet" type="text/css" href="/views/css/wall.css" />
				<link rel="stylesheet" type="text/css" href="/views/cssadds/univers.css" />


				<script type="text/javascript" src="../../js/jquery/jquery.js"/>
				<script type="text/javascript" src="../../js/jquery/iutil.js" />
				<script type="text/javascript" src="../../js/jquery/jquery.interface.js" />
				<script type="text/javascript" src="../../js/jquery/jquery.autocomplete.js" />
				<script type="text/javascript" src="../../js/jquery/jquery.json.js" />
				<script type="text/javascript" src="../../js/jquery/jquery.thickbox.js" />


				<!-- JavaScript Widget Engine -->
				<script type="text/javascript" src="../../js/portal/I18n.js" />
				<script type="text/javascript" src="../../js/portal/engine.js" />
				<script type="text/javascript" src="../../js/portal/EventDispatcher.js" />
				<script type="text/javascript" src="../../js/portal/Widget.js"/>
				<script type="text/javascript" src="../../js/portal/WidgetIcon.js" />
				<script type="text/javascript" src="../../js/portal/WidgetContainer.js" />
				<script type="text/javascript" src="../../js/portal/ConfigParser.js" />
				<script type="text/javascript" src="../../js/portal/WidgetFactory.js" />
				<script type="text/javascript" src="../../js/portal/debug.js" />
				<script type="text/javascript" src="../../js/portal/utils.js" />
				<script type="text/javascript" src="../../js/portal/DragManager.js" />
				<script type="text/javascript" src="../../js/portal/WidgetDragStub.js" />
				<script type="text/javascript" src="../../js/portal/WidgetSeeker.js" />

				<script type="text/javascript">
<![CDATA[
$(document).ready(function(){

    window.portalBaseURI = "../../";

    initWidgetSearch();

    dragManager.initialize ("ghost", "mask", true);

    /* load user interface */
    loadInterface();

    // Initiate Drag & Drop Support
    $('#columns td').Sortable(
        {
            accept: 'widget_container',
            helperclass: 'sort_placeholder',
            opacity: 0.3,
            ghosting: false,
            tolerance: 'intersect',
            handle: 'div.widget_title_container',
            onchange: function(i) { updateInterface(i, 'move'); },
            onStart: function() { displayDragMask(); },
            onStop: function() { hideDragMask(); }
        }
    );
});
]]>
				</script>
                <!--XML extensions-->
                <script type="text/javascript" src="/js/extend/XMLextension.js"/>
				<!--Reverse Ajax-->
				<xsl:if test="doc('input:instance')/groups/@current != 'gr_0'">
                    <script type="text/javascript" src="/js/extend/objectExtension.js"/>
                    <script type="text/javascript" src="/js/extend/engineExtension.js"/>
                    <script type="text/javascript" src="/js/extend/eventReception.js"/>
					<script type="text/javascript" src="../../dwr/interface/GroupEvent.js"/>
					<script type="text/javascript" src="../../dwr/engine.js"/>
					<script type="text/javascript">
<![CDATA[
function init() {
    dwr.engine._pathToDwrServlet=dwr.engine._pathToDwrServlet.replace(/\/dwr/g,"/comet");
    GroupEvent._path=dwr.engine._pathToDwrServlet;
    dwr.engine._scriptSessionId = null;
    eval("dwr.engine._execute(dwr.engine._pathToDwrServlet, '__System', 'pageLoaded', [ function() { dwr.engine._ordered = false; }]);");
    dwr.engine.setActiveReverseAjax(true);
}
]]>
const GROUP = "<xsl:value-of select="doc('input:instance')/groups/@current"/>";
const USERNAME = "<xsl:value-of select="/data/username"/>";
					</script>
				</xsl:if>

			</head>
			<body>
			<xsl:if test="doc('input:instance')/groups/@current != 'gr_0'">
				<xsl:attribute name="onload">init()</xsl:attribute>
			</xsl:if>
				<xsl:variable name="dict" select="/data/translation"/>
				<div id="mask" class="mask_disabled"/>
				<div id="header">
					<div id="organization_name">
						<xsl:value-of select="/data/copName"/>
					</div>

					<img id="logo" src="../../views/img/logo.png"/>
					<a id="header_action" title="Add widgets" href="#TB_inline?width=660&amp;inlineId=widget_search_content&amp;closeCaption={foo:translate('Close', $dict)}">
						<xsl:if test="/data/serviceBrowserUri/@use != 'true'">
							<xsl:attribute name="class">
								<xsl:text>thickbox</xsl:text>
							</xsl:attribute>
						</xsl:if>
						<xsl:if test="/data/serviceBrowserUri/@use = 'true'">
							<xsl:attribute name="href">
								<xsl:value-of select="/data/serviceBrowserUri"/>
							</xsl:attribute>
						</xsl:if>
						<xsl:value-of select="foo:translate('Add widgets', $dict)"/>
					</a>

					<div id="control">
						<ul id="user_info">
							<li>
								<xsl:value-of select="/data/username"/>
							</li>
						</ul>
						<ul>
							<xsl:if test="/data/widgetManagement = 'true'">
								<li>
									<a id="administration" href="/admin/main/">
										<xsl:value-of select="foo:translate('Administration', $dict)"/>
									</a>
								</li>
							</xsl:if>
							<li>
								<a id="preferences" href="/portal/preferences/">
									<xsl:value-of select="foo:translate('My preferences', $dict)"/>
								</a>
							</li>
							<li>
								<a id="help" href="../../index.php/help/index">
									<xsl:value-of select="foo:translate('Online help', $dict)"/>
								</a>
							</li>
						</ul>

						<ul>
							<li>
								<a id="logout" href="../../index.php/users/logout">
									<xsl:value-of select="foo:translate('Logout', $dict)"/>
								</a>
							</li>
						</ul>
					</div>
				</div>
				<xforms:group ref="/list">
                    <!-- Currently some problems sometimes with next line-->
					<!--<div class="mask_enabled" style="background-color:black; opacity:0.5;" onclick="javascript:ORBEON.xforms.Document.dispatchEvent('tr', 'DOMActivate')"/>-->
					<div id="groups_creator">
						<xforms:submit id="tr" appearance="minimal" submission="submit">
							<xforms:label>Close</xforms:label>
						</xforms:submit>
						<h1>Create a new group</h1>
						<xforms:input ref="new/name">
							<xforms:label>Name :</xforms:label>
						</xforms:input>
						<xforms:input ref="new/description">
							<xforms:label>Description :</xforms:label>
						</xforms:input>
						<xforms:submit submission="groups-new">
							<xforms:label>Create !</xforms:label>
						</xforms:submit>
						<h1>Join a group</h1>
						<xforms:repeat id="gr_repeat" nodeset="/list/group">
							<h2>
								<xforms:output ref="name"/>
							</h2>
							<div class="join_button">
								<xforms:trigger>
									<xforms:label>Join !</xforms:label>
									<xforms:action ns1:event="DOMActivate" xmlns:ns1="http://www.w3.org/2001/xml-events">
										<xforms:setvalue ref="./@join">true</xforms:setvalue>
										<xforms:send submission="join-group"/>
									</xforms:action>
								</xforms:trigger>
							</div>
							<span class="description">"<xforms:output ref="description"/>"</span>
							<fieldset>
								<legend>Members :</legend><p>
									<xforms:repeat nodeset="members/member">
										<xforms:output ref="@id"/>
										<br/>
									</xforms:repeat>
								</p>
							</fieldset>
							<fieldset>
								<legend>Widgets :</legend><p>
									<xforms:repeat nodeset="widgets/widget">
										<xforms:output ref="."/>
										<br/>
									</xforms:repeat>
								</p>
							</fieldset>
						</xforms:repeat>
					</div>
				</xforms:group>
				<div id="univers">
					<xforms:select1 id="gr_selector" ref="@current" appearance="full" >
						<xforms:itemset nodeset="instance('groups')/group">
							<xforms:label ref="name"/>
							<xforms:value ref="@id"/>

						</xforms:itemset>
						<xforms:send ns1:event="xforms-value-changed" xmlns:ns1="http://www.w3.org/2001/xml-events" submission="submit"/>
					</xforms:select1>
					<xforms:submit submission="groups-creation">
						<xforms:label>
							<xhtml:img src="/views/img/widget-maximize.png"/>
						</xforms:label>	
					</xforms:submit>
					<xsl:if test="doc('input:instance')/groups/@current != 'gr_0'">
						<span class="leave-button">
							<xforms:submit submission="groups-delete">
								<xforms:label>
									<xhtml:img src="/views/img/control-icon-logout.png"/>
								</xforms:label>
							</xforms:submit>
						</span>
					</xsl:if>
				</div>

				<div id="content">
					<table id="columns" border="1">
						<tr>
							<td id="c_0" class="column first"/>
							<td id="c_1" class="column"/>
							<td id="c_2" class="column"/>
						</tr>
					</table>
				</div>

				<div id="debugWindow"/>
				<div id="ghost"/>

				<div id="widget_search_content">
					<div id="widget_search">
						<div class="info">
							<xsl:value-of select="foo:translate('Click on a widget to add it to your widget wall.', $dict)"/>
						</div>
						<div id="categories">
							<h2>
								<xsl:value-of select="foo:translate('Categories', $dict)"/>
							</h2>
							<ul/>
						</div>

						<div id="results">
							<ul/>
							<div id="navigator">
								<a id="previous_widgets" href="#">
									<xsl:value-of select="foo:translate('Previous', $dict)"/>
								</a><a id="next_widgets" href="#">
									<xsl:value-of select="foo:translate('Next', $dict)"/>
								</a>
							</div>
						</div>
					</div>
				</div>
				<!--<widget:xforms-instance-inspector id="orbeon-xforms-inspector"
    xmlns:widget="http://orbeon.org/oxf/xml/widget"/>-->
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>